﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YArchitech.Plumbing
{
	public partial class FormSeeThePump : System.Windows.Forms.Form
	{
		private void FormSeeThePump_Load(object sender, EventArgs e)
		{
			this.hyPumpGraphChart.InitSeries();
			this.hyPumpGraphChart.ShowXYTitle(false);
			this.hyPumpGraphChart.SetMarker(true);
			this.InitPropertyGrid();
			this.InitPictureBox();
			this.InitDataGridViewBaseParamColumn();
			this.InitDataGridViewQCureLineColumn();
			this.rbtQH.Checked = true;
			this.pumpbase = HYPumpDataManager.GetPumpBaseDataById(this.pumpdata.strFitRvtName, "PumpBase");
			this.rbtDampBase.Checked = true;
			if (File.Exists(this.pumpbase.image))
			{
				this.pictureBoxBasic.Image = new Bitmap(this.pumpbase.image);
				return;
			}
			this.pictureBoxBasic.Image = null;
		}

		private void rbtDampBase_CheckedChanged(object sender, EventArgs e)
		{
			if (!this.rbtDampBase.Checked)
			{
				if (this.rbtBaseFit.Checked)
				{
					this.InitDataGridViewRows(this.pumpdata.strBaseParam, this.dataGridViewBaseParam.Rows);
					if (File.Exists(this.pumpbase.dampimage))
					{
						this.pictureBoxBasic.Image = new Bitmap(this.pumpbase.dampimage);
						return;
					}
					this.pictureBoxBasic.Image = null;
				}
				return;
			}
			this.InitDataGridViewRows(this.pumpdata.strDampBaseParam, this.dataGridViewBaseParam.Rows);
			if (File.Exists(this.pumpbase.image))
			{
				this.pictureBoxBasic.Image = new Bitmap(this.pumpbase.image);
				return;
			}
			this.pictureBoxBasic.Image = null;
		}

		private void rbtALL_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rbtQH.Checked)
			{
				this.dataGridViewCurveLine.Columns[1].HeaderText = "扬程";
				this.InitDataGridViewRows(this.pumpdata.stringHCurve, this.dataGridViewCurveLine.Rows);
				this.hyPumpGraphChart.Draw(this.pumpdata, EPumpCurveType.ePumpCurve_H);
				return;
			}
			if (this.rbtQN.Checked)
			{
				this.dataGridViewCurveLine.Columns[1].HeaderText = "功率";
				this.InitDataGridViewRows(this.pumpdata.stringNCurve, this.dataGridViewCurveLine.Rows);
				this.hyPumpGraphChart.Draw(this.pumpdata, EPumpCurveType.ePumpCurve_N);
				return;
			}
			if (this.rbtQE.Checked)
			{
				this.dataGridViewCurveLine.Columns[1].HeaderText = "效率";
				this.InitDataGridViewRows(this.pumpdata.stringECurve, this.dataGridViewCurveLine.Rows);
				this.hyPumpGraphChart.Draw(this.pumpdata, EPumpCurveType.ePumpCurve_E);
				return;
			}
			if (this.rbtQNPSH.Checked)
			{
				this.dataGridViewCurveLine.Columns[1].HeaderText = "NPSH";
				this.InitDataGridViewRows(this.pumpdata.stringNPSHCurve, this.dataGridViewCurveLine.Rows);
				this.hyPumpGraphChart.Draw(this.pumpdata, EPumpCurveType.ePumpCurve_NPSH);
			}
		}

		private void btnCancle_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		public FormSeeThePump(HYPumpData pumpdata)
		{
			this.InitializeComponent();
			base.Icon = Resource.YArchitechIcon;
			this.pumpdata = pumpdata;
		}

		private void InitPropertyGrid()
		{
			this.propertyGrid.SelectedObject = this.pumpdata;
		}

		private void InitPictureBox()
		{
			if (File.Exists(this.pumpdata.strImage2D))
			{
				this.pictureBox2D.Image = new Bitmap(this.pumpdata.strImage2D);
			}
			else
			{
				this.pictureBox2D.Image = null;
			}
			if (File.Exists(this.pumpdata.strImage3D))
			{
				this.pictureBox3D.Image = new Bitmap(this.pumpdata.strImage3D);
				return;
			}
			this.pictureBox3D.Image = null;
		}

		private void InitDataGridViewQCureLineColumn()
		{
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
			dataGridViewTextBoxColumn.HeaderText = "流量";
			dataGridViewTextBoxColumn.Width = 75;
			dataGridViewTextBoxColumn.SortMode = DataGridViewColumnSortMode.NotSortable;
			dataGridViewTextBoxColumn.ReadOnly = true;
			this.dataGridViewCurveLine.Columns.Add(dataGridViewTextBoxColumn);
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn2 = new DataGridViewTextBoxColumn();
			dataGridViewTextBoxColumn2.HeaderText = "扬程";
			dataGridViewTextBoxColumn2.Width = 75;
			dataGridViewTextBoxColumn2.SortMode = DataGridViewColumnSortMode.NotSortable;
			dataGridViewTextBoxColumn2.ReadOnly = true;
			this.dataGridViewCurveLine.Columns.Add(dataGridViewTextBoxColumn2);
		}

		private void InitDataGridViewBaseParamColumn()
		{
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
			dataGridViewTextBoxColumn.HeaderText = "参数标记名";
			dataGridViewTextBoxColumn.Width = 75;
			dataGridViewTextBoxColumn.SortMode = DataGridViewColumnSortMode.NotSortable;
			dataGridViewTextBoxColumn.ReadOnly = true;
			this.dataGridViewBaseParam.Columns.Add(dataGridViewTextBoxColumn);
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn2 = new DataGridViewTextBoxColumn();
			dataGridViewTextBoxColumn2.HeaderText = "值";
			dataGridViewTextBoxColumn2.Width = 75;
			dataGridViewTextBoxColumn2.SortMode = DataGridViewColumnSortMode.NotSortable;
			dataGridViewTextBoxColumn2.ReadOnly = true;
			this.dataGridViewBaseParam.Columns.Add(dataGridViewTextBoxColumn2);
		}

		private void InitDataGridViewRows(string str, DataGridViewRowCollection rows)
		{
			rows.Clear();
			if (str != "" && str != null)
			{
				new Dictionary<string, string>();
				foreach (KeyValuePair<string, string> keyValuePair in HYPumpDataManager.ConvertStringToDic(str))
				{
					object[] values = new object[]
					{
						keyValuePair.Key,
						keyValuePair.Value
					};
					rows.Add(values);
				}
			}
		}

		private HYPumpData pumpdata = new HYPumpData();

		private HYPumpBase pumpbase = new HYPumpBase();
	}
}
